<template>
<div id="background">
    <el-container>
        <el-header>
             <!-- <van-swipe id="shiCaoNewsHeight">
                  <van-swipe-item v-for="news  in newsPics" :key="news.newsId" >
                    <img v-bind:src="news.newsPicture" style="width:100%"  />
                  </van-swipe-item>
                </van-swipe> -->
                <div style="position:relative">
                    <!-- <img v-bind:src="newsPicture" id="shiCaoNewsHeight" style="width:100%;height:200px"/> -->
                      <el-image
                        style="width: 100%; height: 200px"
                        :src="newsPicture"
                        fit="cover">
                    </el-image>
                    <div style="position:absolute;left:0;top:0;right:0" id="shiCaoIntroduceHead">
                        <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                            <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                            <img v-bind:src="backIcon" class="backSize" @click="back"/>
                            </el-col>
                            <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                            <span class="titleSize">培训介绍</span>
                            </el-col>
                        </el-row>
                         <!-- <van-tabs v-model="activeKeCi" swipeable animated color="#53cdf5"  @change="showKeCi" style="width:100%" id="shiCaoTab">
                            <van-tab v-for="index in keCis" v-bind:key="index.id" :title="index.name" :name="index.id"></van-tab>
                        </van-tabs> -->
                    </div>
                    <div style="position:absolute;bottom:0px;left:0;right:0;top:156px">
                        <van-tabs v-model="activeKeCi" swipeable animated color="rgb(255,255,255,0)"  @change="showKeCi" style="width:100%" id="shiCaoIntroduceTab">
                            <van-tab v-for="index in keCis" v-bind:key="index.id" :title="index.name" :name="index.id">
                                 <el-scrollbar style="margin-top:20px">
                                    <div>
                                        <el-row type="flex" class="imgCol">
                                            <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                                                <div class="point"></div>
                                            </el-col>
                                            <el-col  :xs="22" :sm="22" :md="22" >
                                                <span class='words'>培训介绍</span>
                                            </el-col>
                                        </el-row>
                                        <div class="shiCaoWordsBox">
                                            <span class="words">{{intro}}</span>
                                        </div>
                                    </div>
                                    <div>
                                        <el-row type="flex" class="imgCol">
                                            <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                                                <div class="point"></div>
                                            </el-col>
                                            <el-col  :xs="22" :sm="22" :md="22" >
                                                <span class='words'>课次说明</span>
                                            </el-col>
                                        </el-row>
                                        <div class="shiCaoWordsBox">
                                            <span class="words">{{peiXun.shuoMing}}</span>
                                        </div>
                                    </div>
                                    <div>
                                        <el-row type="flex" class="imgCol">
                                            <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                                                <div class="point"></div>
                                            </el-col>
                                            <el-col  :xs="22" :sm="22" :md="22" >
                                                <span class='words'>报名要求</span>
                                            </el-col>
                                        </el-row>
                                        <div class="shiCaoWordsBox" v-for="i in peiXun.needs.length" v-bind:key='i'>
                                            <span class="words">{{peiXun.needs[i-1]}}</span>
                                        </div>
                                    </div>
                                </el-scrollbar>
                            </van-tab>
                        </van-tabs>
                    </div>
                </div>
        </el-header>
        <el-main id="shiCaoIntroduceMain" style="margin-top:170px">
            <!-- <el-scrollbar>
                <div>
                    <el-row type="flex" class="imgCol">
                        <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                            <div class="point"></div>
                        </el-col>
                        <el-col  :xs="22" :sm="22" :md="22" >
                            <span class='words'>培训介绍</span>
                        </el-col>
                    </el-row>
                    <div class="shiCaoWordsBox">
                        <span class="words">{{peiXun.intro}}</span>
                    </div>
                </div>
                <div>
                    <el-row type="flex" class="imgCol">
                        <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                            <div class="point"></div>
                        </el-col>
                        <el-col  :xs="22" :sm="22" :md="22" >
                            <span class='words'>课次说明</span>
                        </el-col>
                    </el-row>
                    <div class="shiCaoWordsBox">
                        <span class="words">{{peiXun.shuoMing}}</span>
                    </div>
                </div>
                 <div>
                    <el-row type="flex" class="imgCol">
                        <el-col :xs="2" :sm="2" :md="2" :offset="1" >
                            <div class="point"></div>
                        </el-col>
                        <el-col  :xs="22" :sm="22" :md="22" >
                            <span class='words'>报名要求</span>
                        </el-col>
                    </el-row>
                    <div class="shiCaoWordsBox">
                        <span class="words">{{peiXun.needs}}</span>
                    </div>
                </div>
            </el-scrollbar> -->
        </el-main>
        <el-footer id="shiCaoIntroduceFoot">
            <el-row type="flex" class="imgCol" style="position:fixed;bottom:10px;width:100%">
                <button class="btnShiCaoIntroduce" @click="goToSearchPeiXun">查询</button>
            </el-row>
        </el-footer>
    </el-container>
</div>
</template>
<script>
import { Swipe, SwipeItem ,Toast} from 'vant';
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
export default {
    data(){
        return{
            trainId:0,
            //绑定tab条内容
            activeKeCi:'',
            keCis:[],
            keCisNo:[],
            //绑定课次号
            classNo:'',
            //绑定显示的内容
            intro:'',
            peiXun:{
               // intro:'低压电工操作证培训共需要经历10次线下实操培训，这是其中的一次课，该课程主要讲解巴拉巴拉巴拉。。。',
                //shuoMing:'低压电工操作证培训根据培训内容及难易程度被划分成10次，学员参与了第一次培训后，课解锁报名第二次培训，一次类推。如果学员认为对某次培训内容掌握的不过透彻，可重复报名该次培训',
                //needs:'1234'
                shuoMing:'',
                needs:'',
            },
            backIcon:backIcon,
            //newsPicture:'https://img.yzcdn.cn/vant/apple-1.jpg',
            newsPicture:'',
        }
    },
    mounted(){
        var trainId=this.$route.query.trainId;
        if(trainId!=null){
            this.trainId=trainId;
            console.log('工种id：'+this.trainId);
        }
        this.getClassAndIntro();


        var normalHeight=document.documentElement.clientHeight;
        var bg = document.getElementById("background");
        this.normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height =normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

 
          //var head=document.getElementById("shiCaoHead");
          //var news=document.getElementById("shiCaoNewsHeight");
          var head=document.getElementById("shiCaoIntroduceHead");
          var main=document.getElementById("shiCaoIntroduceMain");
          var headHeight=normalHeight/30*4;
          var mainHeight=normalHeight/30*20;
 
          head.style.height=headHeight+'px';
        //  news.style.height=newsHight+'px';
         //   main.style.height=mainHeight+'px';
    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        //切换课次的回调函数
        showKeCi(name){
            this.classNo=name;
            console.log('课次号：'+name);
            //每次切换课次时，仅置空课次说明和课次要求
            this.peiXun.shuoMing='';
            this.peiXun.needs='';
            this.getClassDetail();
        },
        goToSearchPeiXun(){
            this.$router.push({
                path:'/shiCao/search',
                query:{
                    trainId:this.trainId,
                    trainClassNo:this.classNo
                }
            })
          
        },
        //获取课次和培训介绍
        getClassAndIntro(){
            var URL=this.IP.IP+'/train/getTrainInformation';
            console.log(URL);
            console.log(this.trainId);
            this.$ajax({
                method:'get',
                url:URL,
                params:{
                    trainId:this.trainId
                }
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                   this.intro=response.data.data.trainIntroduction;
                   this.keCisNo=response.data.data.trainClassNo;
                   var i=0,j=1;
                   for(i=0;i<this.keCisNo.length;i++){
                       this.keCis.push({id:this.keCisNo[i],name:'第'+j+'课次'});
                       j++;
                   }
                   this.classNo=this.keCisNo[0];
                   console.log('课次号'+this.classNo);
                    this.getClassDetail();
                }else{
                   Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //根据工种id和课次id获取课次说明、要求和图片
        getClassDetail(){
            var URL=this.IP.IP+'/train/getTrainClassInformation';
            console.log(URL);
            console.log(this.trainId);
            console.log(this.classNo);
            this.$ajax({
                method:'get',
                url:URL,
                params:{
                    trainId:this.trainId,
                    trainClassNo:this.classNo
                }
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                  this.newsPicture=response.data.data.trainPicture;
                  this.peiXun.shuoMing=response.data.data.trainClassText;
                  this.peiXun.needs=response.data.data.trainClassRequest;
                }else{
                   Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        }
    }
}
</script>
<style>
.el-footer{
    padding:0px;
}
.btnShiCaoIntroduce{
        background-color: #53cdf5;
    height: 40px;
    width: 80%;
    color: #fff;
    font-size: 1.125em;
    outline: none;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    -ms-border-radius: 25px;
    -o-border-radius: 25px;
    border-radius: 25px;
    border-style: none;
}
.shiCaoWordsBox{
    margin: 10px;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
.words{
    color: #707070;
}
.point{
 width: 10px !important;      
 height: 10px !important;      
 background-color:#53cdf5 !important;      
 border-radius: 50% !important;      
 -moz-border-radius: 50% !important;      
 -webkit-border-radius: 50% !important; 
  box-shadow: none;
}
.van-swipe__indicator--active {
    background-color: #fff;
}
#shiCaoIntroduceTab .van-tabs__nav {
    background-color: rgb(255,255,255,0);
}
#shiCaoIntroduceTab .van-tab--active {
  
    background-color: #fff;
}
#shiCaohead{
    background-color: rgb(255,255,255,0);
}
.el-main{
    padding: 0px;
  
}
.el-header{
    padding: 0px;
}
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>
